﻿using System;
using System.Collections.Generic;
using AutoMapper;
using CodeSaude.Application.Interfaces;
using CodeSaude.Application.ViewModels;
using CodeSaude.Domain.Entities;
using CodeSaude.Domain.Interfaces.Service;

namespace CodeSaude.Application.Services
{
    public class MenuApplicationService : BaseApplicationService,  IMenuApplicationService
    {
        private readonly IMenuService _menuService;

        public MenuApplicationService(IMenuService menuService)
        {
            _menuService = menuService;
        }

        //public ValidationApplicationResult Add(GrupoUsuarioViewModel GrupoUsuarioViewModel)
        //{
        //    var usuario = Mapper.Map<GrupoUsuarioViewModel, Usuario>(GrupoUsuarioViewModel);

        //    var result = _usuarioService.AdicionarUsuario(usuario);

        //    //if(result.IsValid)
        //        _usuarioService.SaveChanges();

        //    return Mapper.Map<ValidationResult, ValidationApplicationResult>(result);
        //}

        public void Add(MenuViewModel MenuViewModel)
        {
            var Menu = Mapper.Map<MenuViewModel, Menu>(MenuViewModel);

            BeginTransaction();
            _menuService.AdicionarMenu(Menu);
            Commit();
        }

        public MenuViewModel GetById(int id)
        {
            return Mapper.Map<MenuViewModel>(_menuService.GetById(id));
        }

        public IEnumerable<MenuViewModel> GetAll()
        {
            return Mapper.Map<IEnumerable<MenuViewModel>>(_menuService.GetAll());
        }

        public void Update(MenuViewModel MenuViewModel)
        {
            var Menu = Mapper.Map<Menu>(MenuViewModel);

            BeginTransaction();
            _menuService.Update(Menu);
            Commit();
        }

        public void Remove(MenuViewModel MenuViewModel)
        {
            var user = _menuService.GetById(MenuViewModel.MenuId);
            BeginTransaction();
            _menuService.Remove(user);
            Commit();
        }

        public void Dispose()
        {
            _menuService.Dispose();
        }
    }
}
